<script>
// 任务一、答题页面
export default {
  name: "TxOneComm",
  data(){
    return {
        show_aq:false,
        question:'',
        show_btn1:true,
        show_card1:false,
        show_card2:false,
        start_time:'',
        end_time:'',
        first:'',
        second:'',
        thrid:''
    }
  },

  methods:{
      //显示答题组件
      show_comm(question){
            this.question = question;
            var letters = question.textQuestion.split("");
            if(letters[0]){
                this.first = letters[0]
            }
            if(letters[1]){
              this.second = letters[1]
            }
            if(letters[2]){
              this.thrid = letters[2]
            }
            this.show_aq = true;
            this.show_btn1 = true;
            this.hide_btn();
        },




      // +号按钮300毫秒后消失
      hide_btn(){
          const _this = this;
          this.$nextTick(function(){
              setTimeout(function(){
                _this.show_btn1 = false;
                _this.show_card1 = true;
                _this.start_time = new Date().getTime();
              },300)
          })
      },

      //用户选择答案，并统计用户答题时长
      choose_answer(ans){
          //统计结束时间
          this.end_time = new Date().getTime();
          var spend_time = Math.abs(this.end_time - this.start_time);
          //统计答案是否正确
          var is_right = '是';
          if(this.question.rightAnswer != ans){
            is_right = '否';
          }

          //显示空屏
          this.show_card1 = false;
          this.show_card2 = true;

          //300毫秒后，空屏隐藏，进入下一题
          const _this = this;
          this.$nextTick(function(){
            setTimeout(function(){
              _this.clsar_data();
              _this.$emit('ans_finish',ans,spend_time,is_right); //空屏显示300ms之后，回调父函数，传给父元素答案，并告知父元素进入下一题
            },300)
          })
      },

      //答题完成---清空答题组件
      clsar_data(){
            this.show_aq = false;
            this.question='';
            this.show_btn1=true;
            this.show_card1=false;
            this.show_card2=false;
      }


  }
}
</script>

<template>
      <div ref="div_one" v-if="show_aq" style="width: 50%;">
        <div v-if="show_btn1" class="card1_plus">
            <div  ref="btn1" class="card1_btn1" >+</div>
        </div>

         <div v-if="show_card1" class="card1">
              <div class="que_sty">
<!--                <span>{{question.textQuestion}}</span>-->
                <span v-if="first!=''">{{first}}</span>
                <span v-if="second!=''">&nbsp;{{second}}</span>
                <span v-if="thrid!=''">&nbsp;{{thrid}}</span>
              </div>
              <div class="div_btn1">
                <div>
                  <el-button class="btn2" type="primary" @click="choose_answer('是')">是</el-button>
                  <p v-if="question.taskType==1" style="font-size: 40px;margin-top: 20px">(身体相关)</p>
                  <p v-if="question.taskType==5" style="font-size: 40px;margin-top: 20px">&nbsp;(有这个词)&nbsp;</p>
                </div>
                <div>
                 <el-button class="btn2" type="primary" @click="choose_answer('否')">否</el-button>
                  <p v-if="question.taskType==1" style="font-size: 40px;margin-top: 20px">(身体无关)</p>
                  <p v-if="question.taskType==5" style="font-size: 40px;margin-top: 20px">(没有这个词)</p>
                </div>
              </div>
         </div>
        <!--         空屏显示300毫秒-->
        <div v-if="show_card2" class="card1"></div>
      </div>
</template>

<style scoped>
  .card1_btn1{
    width: 200px;
    height: 200px;
    line-height: 170px;
    font-size: 250px;
    color:red;
    //background-color: #f80258;
  }
  .card1_plus{
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 25%;
  }
  .card1{
    text-align: center;
    width: 100%;
  }
  .que_sty{
    color: #050505;
    font-size: 160px;
    font-weight: 700;
    margin-top: -40px;
  }
  .sub_title{
    font-size: 50px;
  }

  .div_btn1{
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
  }
  .btn2{
    width: 100%;
    height: 90px;
    font-size: 60px;
    display: inline-block;
  }

</style>